package com.zhangh.summer.admin.controller.app;

import com.zhangh.summer.admin.biz.app.AppBiz;
import com.zhangh.summer.admin.biz.role.RoleBiz;
import com.zhangh.summer.admin.model.bo.DataBO;
import com.zhangh.summer.admin.model.bo.NoValidatorBO;
import com.zhangh.summer.admin.model.enums.AppFrameEnum;
import com.zhangh.summer.admin.model.po.AdAppPO;
import com.zhangh.summer.admin.model.po.AdRolePO;
import com.zhangh.summer.admin.support.base.JsonResponse;
import com.zhangh.summer.admin.support.ds.common.pager.DataPager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: TODO
 * @author: zhanghui  zhanghlucky@163.com
 * @create: 2021-10-08 21:44
 **/
@RestController
@RequestMapping(value = "/app",method = RequestMethod.POST)
public class AppController {
    @Autowired
    private AppBiz appBiz;

    @RequestMapping("/dataPager")
    public String dataPager(@RequestBody DataBO query) {
        DataPager<AdAppPO> dataPager=this.appBiz.getAppDataPager(query,query.getPager());
        return new JsonResponse().toJson(dataPager);
    }

    @RequestMapping("/getApp/{id}")
    public String getApp(@PathVariable Long id) {
        AdAppPO adAppPO=this.appBiz.getAdAppPO(id);
        return new JsonResponse().toJson(adAppPO);
    }

    @RequestMapping("/save")
    public String save(@RequestBody AdAppPO adAppPO) {
        long c1=this.appBiz.saveApp(adAppPO);
        return new JsonResponse().toJson(c1);
    }

    @RequestMapping("/update")
    public String update(@RequestBody AdAppPO adAppPO) {
        int c1=this.appBiz.updateApp(adAppPO);
        return new JsonResponse().toJson(c1);
    }

    @RequestMapping("/delete")
    public String delete(@RequestBody DataBO dataBO) {
        int c1=this.appBiz.deleteApp(dataBO.getId());
        return new JsonResponse().toJson(c1);
    }

    @RequestMapping("/validateAppCode")
    public String validateAppCode(@RequestBody NoValidatorBO noValidatorBO) {
        boolean bl=this.appBiz.validateAppCode(noValidatorBO);
        return new JsonResponse().toJson(bl);
    }

    @RequestMapping("/getMicroAppList")
    public String getMicroAppList() {
        List<AdAppPO> list=this.appBiz.getAdAppPOList(AppFrameEnum.MICRO.getValue());
        return new JsonResponse().toJson(list);
    }
    @RequestMapping("/getAppList")
    public String getAppList() {
        List<AdAppPO> list=this.appBiz.getAdAppPOList(0);
        return new JsonResponse().toJson(list);
    }



}
